/*=========================================================================
Elite College as Engines of Upward Mobility: Evidence from Colombia's Ser Pilo Paga
Authors: Juliana Londoño-Vélez, Catherine Rodriguez, Fabio Sánchez
and Luis Esteban Álvarez-Arango

Creation date: June 6th, 2025
--------------------------------------------------------------------------
Figures A11a, A11b, A11c, A11d, A11e, A11f, A11g and A11h
=========================================================================*/

use "${data}/data_RD", clear
keep if icfes_per==20122 | icfes_per==20132
tab icfes_per
drop if m==1
drop if icfes_stratum=="Sin Estrato"
drop if puntaje_global_s11_final==.

fasterxtile decile122=puntaje_global_s11_final if icfes_per==20122, nq(10)
fasterxtile decile132=puntaje_global_s11_final if icfes_per==20132, nq(10)
gen decile=decile122
replace decile=decile132 if icfes_per==20132
drop decile1*

gegen aux=tag(codigo_ies icfes_per) if access_0==1
gegen nump=total(aux), by(codigo_ies)
tab nump,m
keep if nump==2 | nump==0
drop if codigo_ies!=. & nump==0

gen d_post=(icfes_per==20132)
replace codigo_programa=. if access_6==0
replace codigo_programa=0 if codigo_programa==.

replace decile=5 if decile<5
gen d0=.
gen d1=.
forvalues i=5/10{
	replace d0=`i' + 0.1 in `=`i'-4'
	replace d1=`i' - 0.1 in `=`i'-4'
	gen post_d`i'=(d_post==1 & decile==`i')
}

label define d0 5 "5 and below"
label values d0 d0

forvalues j=0/1{
	reghdfe access_0_hq post_d6 post_d7 post_d8 post_d9 post_d10  if eligible_sisben==`j', abs(i.icfes_per i.decile) vce(robust)
	cap drop b`j' ub`j' lb`j'
	matrix list e(b)
	foreach i in b se{
		mat `i'`j' = [0\_`i'[post_d6]\_`i'[post_d7]\_`i'[post_d8]\_`i'[post_d9]\_`i'[post_d10]]
	}
	mat ub`j' = b`j'+((1.96)*se`j')
	mat lb`j' = b`j'-((1.96)*se`j')
	mat data`j' = [b`j', ub`j', lb`j']
	svmat data`j'
	rename data`j'1 b`j'
	rename data`j'2 ub`j'
	rename data`j'3 lb`j'
}

recode ub0 ub1 lb0 lb1 (0=.)

#delimit ;
twoway 	(scatter b0 d0 if !missing(b0), color(blue) m(Th) lwidth(thick) msize(medlarge))
		(rcap ub0 lb0 d0 if !missing(b0), color(blue) m(o) msiz(vlarge) lwidth(medthick))
		(scatter b1 d1 if !missing(b1), color(red) m(o) lwidth(thick) msize(medlarge))
		(rcap ub1 lb1 d1 if !missing(b1), color(red) m(o) msiz(vlarge) lwidth(medthick))
		, ytitle(DD Coefficient and 95% CI) xtitle(SABER 11 Decile) 
		xlab(5(1)10, valuelabel) ysc(r(-.05 .15)) ylab(-.05(.05).15) xsize(8) 
		legend(order(3 "Low SES" 1 "High SES")
		position(10) ring(0) size(medlarge))
		yline(0, lc(gray) lpattern(dash) lwidth(thin))
;
#delimit cr
graph export "${outcomes}/FigA11a.pdf", replace

forvalues j=0/1{
	reghdfe access_6 post_d6 post_d7 post_d8 post_d9 post_d10  if eligible_sisben==`j', abs(i.icfes_per i.decile) vce(robust)
	cap drop b`j' ub`j' lb`j'
	matrix list e(b)
	foreach i in b se{
		mat `i'`j' = [0\_`i'[post_d6]\_`i'[post_d7]\_`i'[post_d8]\_`i'[post_d9]\_`i'[post_d10]]
	}
	mat ub`j' = b`j'+((1.96)*se`j')
	mat lb`j' = b`j'-((1.96)*se`j')
	mat data`j' = [b`j', ub`j', lb`j']
	svmat data`j'
	rename data`j'1 b`j'
	rename data`j'2 ub`j'
	rename data`j'3 lb`j'
}

recode ub0 ub1 lb0 lb1 (0=.)

#delimit ;
twoway 	(scatter b0 d0 if !missing(b0), color(blue) m(Th) lwidth(thick) msize(medlarge))
		(rcap ub0 lb0 d0 if !missing(b0), color(blue) m(o) msiz(vlarge) lwidth(medthick))
		(scatter b1 d1 if !missing(b1), color(red) m(o) lwidth(thick) msize(medlarge))
		(rcap ub1 lb1 d1 if !missing(b1), color(red) m(o) msiz(vlarge) lwidth(medthick))
		, ytitle(DD Coefficient and 95% CI) xtitle(SABER 11 Decile) 
		xlab(5(1)10, valuelabel) ysc(r(-.05 .15)) ylab(-.05(.05).15) xsize(8) 
		legend(order(3 "Low SES" 1 "High SES")
		position(10) ring(0) size(medlarge))
		yline(0, lc(gray) lpattern(dash) lwidth(thin))
;
#delimit cr
graph export "${outcomes}/FigA11b.pdf", replace

forvalues j=0/1{
	reghdfe graduation_exam_pro_7_hq post_d6 post_d7 post_d8 post_d9 post_d10  if eligible_sisben==`j', abs(i.icfes_per i.decile) vce(robust)
	cap drop b`j' ub`j' lb`j'
	matrix list e(b)
	foreach i in b se{
		mat `i'`j' = [0\_`i'[post_d6]\_`i'[post_d7]\_`i'[post_d8]\_`i'[post_d9]\_`i'[post_d10]]
	}
	mat ub`j' = b`j'+((1.96)*se`j')
	mat lb`j' = b`j'-((1.96)*se`j')
	mat data`j' = [b`j', ub`j', lb`j']
	svmat data`j'
	rename data`j'1 b`j'
	rename data`j'2 ub`j'
	rename data`j'3 lb`j'
}

recode ub0 ub1 lb0 lb1 (0=.)

#delimit ;
twoway 	(scatter b0 d0 if !missing(b0), color(blue) m(Th) lwidth(thick) msize(medlarge))
		(rcap ub0 lb0 d0 if !missing(b0), color(blue) m(o) msiz(vlarge) lwidth(medthick))
		(scatter b1 d1 if !missing(b1), color(red) m(o) lwidth(thick) msize(medlarge))
		(rcap ub1 lb1 d1 if !missing(b1), color(red) m(o) msiz(vlarge) lwidth(medthick))
		, ytitle(DD Coefficient and 95% CI) xtitle(SABER 11 Decile) 
		xlab(5(1)10, valuelabel) ysc(r(-.05 .15)) ylab(-.05(.05).15) xsize(8) 
		legend(order(3 "Low SES" 1 "High SES")
		position(10) ring(0) size(medlarge))
		yline(0, lc(gray) lpattern(dash) lwidth(thin))
;
#delimit cr
graph export "${outcomes}/FigA11c.pdf", replace

forvalues j=0/1{
	reghdfe graduation_exam_pro_7 post_d6 post_d7 post_d8 post_d9 post_d10  if eligible_sisben==`j', abs(i.icfes_per i.decile) vce(robust)
	cap drop b`j' ub`j' lb`j'
	matrix list e(b)
	foreach i in b se{
		mat `i'`j' = [0\_`i'[post_d6]\_`i'[post_d7]\_`i'[post_d8]\_`i'[post_d9]\_`i'[post_d10]]
	}
	mat ub`j' = b`j'+((1.96)*se`j')
	mat lb`j' = b`j'-((1.96)*se`j')
	mat data`j' = [b`j', ub`j', lb`j']
	svmat data`j'
	rename data`j'1 b`j'
	rename data`j'2 ub`j'
	rename data`j'3 lb`j'
}

recode ub0 ub1 lb0 lb1 (0=.)

#delimit ;
twoway 	(scatter b0 d0 if !missing(b0), color(blue) m(Th) lwidth(thick) msize(medlarge))
		(rcap ub0 lb0 d0 if !missing(b0), color(blue) m(o) msiz(vlarge) lwidth(medthick))
		(scatter b1 d1 if !missing(b1), color(red) m(o) lwidth(thick) msize(medlarge))
		(rcap ub1 lb1 d1 if !missing(b1), color(red) m(o) msiz(vlarge) lwidth(medthick))
		, ytitle(DD Coefficient and 95% CI) xtitle(SABER 11 Decile) 
		xlab(5(1)10, valuelabel) ysc(r(-.05 .15)) ylab(-.05(.05).15) xsize(8) 
		legend(order(3 "Low SES" 1 "High SES")
		position(10) ring(0) size(medlarge))
		yline(0, lc(gray) lpattern(dash) lwidth(thin))
;
#delimit cr
graph export "${outcomes}/FigA11d.pdf", replace

forvalues j=0/1{
	reghdfe score_saberpro_5 post_d6 post_d7 post_d8 post_d9 post_d10  if eligible_sisben==`j', abs(i.icfes_per i.decile) vce(robust)
	cap drop b`j' ub`j' lb`j'
	matrix list e(b)
	foreach i in b se{
		mat `i'`j' = [0\_`i'[post_d6]\_`i'[post_d7]\_`i'[post_d8]\_`i'[post_d9]\_`i'[post_d10]]
	}
	mat ub`j' = b`j'+((1.96)*se`j')
	mat lb`j' = b`j'-((1.96)*se`j')
	mat data`j' = [b`j', ub`j', lb`j']
	svmat data`j'
	rename data`j'1 b`j'
	rename data`j'2 ub`j'
	rename data`j'3 lb`j'
}

recode ub0 ub1 lb0 lb1 (0=.)

#delimit ;
twoway 	(scatter b0 d0 if !missing(b0), color(blue) m(Th) lwidth(thick) msize(medlarge))
		(rcap ub0 lb0 d0 if !missing(b0), color(blue) m(o) msiz(vlarge) lwidth(medthick))
		(scatter b1 d1 if !missing(b1), color(red) m(o) lwidth(thick) msize(medlarge))
		(rcap ub1 lb1 d1 if !missing(b1), color(red) m(o) msiz(vlarge) lwidth(medthick))
		, ytitle(DD Coefficient and 95% CI) xtitle(SABER 11 Decile) 
		xlab(5(1)10, valuelabel) ylab(-0.05(0.05)0.15) xsize(8) 
		legend(order(3 "Low SES" 1 "High SES")
		position(10) ring(0) size(medlarge))
		yline(0, lc(gray) lpattern(dash) lwidth(thin))
;
#delimit cr
graph export "${outcomes}/FigA11e.pdf", replace

forvalues j=0/1{
	reghdfe work_9 post_d6 post_d7 post_d8 post_d9 post_d10  if eligible_sisben==`j', abs(i.icfes_per i.decile) vce(robust)
	cap drop b`j' ub`j' lb`j'
	matrix list e(b)
	foreach i in b se{
		mat `i'`j' = [0\_`i'[post_d6]\_`i'[post_d7]\_`i'[post_d8]\_`i'[post_d9]\_`i'[post_d10]]
	}
	mat ub`j' = b`j'+((1.96)*se`j')
	mat lb`j' = b`j'-((1.96)*se`j')
	mat data`j' = [b`j', ub`j', lb`j']
	svmat data`j'
	rename data`j'1 b`j'
	rename data`j'2 ub`j'
	rename data`j'3 lb`j'
}

recode ub0 ub1 lb0 lb1 (0=.)

#delimit ;
twoway 	(scatter b0 d0 if !missing(b0), color(blue) m(Th) lwidth(thick) msize(medlarge))
		(rcap ub0 lb0 d0 if !missing(b0), color(blue) m(o) msiz(vlarge) lwidth(medthick))
		(scatter b1 d1 if !missing(b1), color(red) m(o) lwidth(thick) msize(medlarge))
		(rcap ub1 lb1 d1 if !missing(b1), color(red) m(o) msiz(vlarge) lwidth(medthick))
		, ytitle(DD Coefficient and 95% CI) xtitle(SABER 11 Decile) 
		xlab(5(1)10, valuelabel) ylab(-0.05(0.05)0.1) xsize(8) 
		legend(order(3 "Low SES" 1 "High SES")
		position(10) ring(0) size(medlarge))
		yline(0, lc(gray) lpattern(dash) lwidth(thin))
;
#delimit cr
graph export "${outcomes}/FigA11f.pdf", replace

forvalues j=0/1{
	reghdfe mw_9 post_d6 post_d7 post_d8 post_d9 post_d10  if eligible_sisben==`j', abs(i.icfes_per i.decile) vce(robust)
	cap drop b`j' ub`j' lb`j'
	matrix list e(b)
	foreach i in b se{
		mat `i'`j' = [0\_`i'[post_d6]\_`i'[post_d7]\_`i'[post_d8]\_`i'[post_d9]\_`i'[post_d10]]
	}
	mat ub`j' = b`j'+((1.96)*se`j')
	mat lb`j' = b`j'-((1.96)*se`j')
	mat data`j' = [b`j', ub`j', lb`j']
	svmat data`j'
	rename data`j'1 b`j'
	rename data`j'2 ub`j'
	rename data`j'3 lb`j'
}

recode ub0 ub1 lb0 lb1 (0=.)

#delimit ;
twoway 	(scatter b0 d0 if !missing(b0), color(blue) m(Th) lwidth(thick) msize(medlarge))
		(rcap ub0 lb0 d0 if !missing(b0), color(blue) m(o) msiz(vlarge) lwidth(medthick))
		(scatter b1 d1 if !missing(b1), color(red) m(o) lwidth(thick) msize(medlarge))
		(rcap ub1 lb1 d1 if !missing(b1), color(red) m(o) msiz(vlarge) lwidth(medthick))
		, ytitle(DD Coefficient and 95% CI) xtitle(SABER 11 Decile) 
		xlab(5(1)10, valuelabel) ylab(-0.05(0.05)0.25) xsize(8) 
		legend(order(3 "Low SES" 1 "High SES")
		position(10) ring(0) size(medlarge))
		yline(0, lc(gray) lpattern(dash) lwidth(thin))
;
#delimit cr
graph export "${outcomes}/FigA11g.pdf", replace

forvalues j=0/1{
	reghdfe ln_wage_9 post_d6 post_d7 post_d8 post_d9 post_d10  if eligible_sisben==`j', abs(i.icfes_per i.decile) vce(robust)
	cap drop b`j' ub`j' lb`j'
	matrix list e(b)
	foreach i in b se{
		mat `i'`j' = [0\_`i'[post_d6]\_`i'[post_d7]\_`i'[post_d8]\_`i'[post_d9]\_`i'[post_d10]]
	}
	mat ub`j' = b`j'+((1.96)*se`j')
	mat lb`j' = b`j'-((1.96)*se`j')
	mat data`j' = [b`j', ub`j', lb`j']
	svmat data`j'
	rename data`j'1 b`j'
	rename data`j'2 ub`j'
	rename data`j'3 lb`j'
}

recode ub0 ub1 lb0 lb1 (0=.)

#delimit ;
twoway 	(scatter b0 d0 if !missing(b0), color(blue) m(Th) lwidth(thick) msize(medlarge))
		(rcap ub0 lb0 d0 if !missing(b0), color(blue) m(o) msiz(vlarge) lwidth(medthick))
		(scatter b1 d1 if !missing(b1), color(red) m(o) lwidth(thick) msize(medlarge))
		(rcap ub1 lb1 d1 if !missing(b1), color(red) m(o) msiz(vlarge) lwidth(medthick))
		, ytitle(DD Coefficient and 95% CI) xtitle(SABER 11 Decile) 
		xlab(5(1)10, valuelabel) ylab(-0.05(0.05)0.25) xsize(8) 
		legend(order(3 "Low SES" 1 "High SES")
		position(10) ring(0) size(medlarge))
		yline(0, lc(gray) lpattern(dash) lwidth(thin))
;
#delimit cr
graph export "${outcomes}/FigA11h.pdf", replace
